package com.baoteng.network.executor;

import android.content.Context;

import com.baoteng.network.callback.FileCallback;
import com.baoteng.network.callback.StringCallback;
import com.baoteng.network.model.HttpPriority;

import java.io.File;
import java.util.List;
import java.util.Map;

import okhttp3.OkHttpClient;

/**
 * Author: loren
 * Date: 2019/8/14
 * <p>
 * 提供给外部调用的请求执行类
 */
public class HttpExecutor implements IHttpEngine {

    private static volatile HttpExecutor sInstance;

    public static HttpExecutor getDefault() {
        if (sInstance != null) {
            return sInstance;
        } else {
            synchronized (HttpExecutor.class) {
                if (sInstance == null) {
                    sInstance = new HttpExecutor();
                }
                return sInstance;
            }
        }
    }

    private final IHttpEngine httpEngine;

    private HttpExecutor() {
        httpEngine = HttpEngineImpl.instance();
    }

    @Override
    public void init(Context context) {
        if (context == null) {
            throw new RuntimeException("XmHttp Context is null");
        }
        httpEngine.init(context);
    }

    @Override
    public void cancelTag(Object tag) {
        httpEngine.cancelTag(tag);
    }

    @Override
    public void cancelAll() {
        httpEngine.cancelAll();
    }

    @Override
    public void addCommonParams(Map<String, String> params) {
        httpEngine.addCommonParams(params);
    }

    @Override
    public void clearCommonParams() {
        httpEngine.clearCommonParams();
    }

    @Override
    public void addCommonParams(String key, String value) {
        httpEngine.addCommonParams(key, value);
    }

    @Override
    public void removeCommonParams(String key) {
        httpEngine.removeCommonParams(key);
    }

    @Override
    public void addCommonHeader(String name, String value) {
        httpEngine.addCommonHeader(name, value);
    }

    @Override
    public void addCommonHeaders(Map<String, String> params) {
        httpEngine.addCommonHeaders(params);
    }

    @Override
    public void removeCommonHeader(String name) {
        httpEngine.removeCommonHeader(name);
    }

    @Override
    public void clearCommonHeaders() {
        httpEngine.clearCommonHeaders();
    }

    @Override
    public OkHttpClient getHttpClient() {
        return httpEngine.getHttpClient();
    }

    @Override
    public OkHttpClient getDownloadClient() {
        return httpEngine.getDownloadClient();
    }

    @Override
    public Context getContext() {
        return httpEngine.getContext();
    }

    @Override
    public void getString(String url, StringCallback callBack) {
        httpEngine.getString(url, callBack);
    }

    @Override
    public void getString(String url, Map<String, Object> params, StringCallback callBack) {
        httpEngine.getString(url, params, callBack);
    }

    @Override
    public void getString(String url, Map<String, Object> params, String tag, StringCallback callBack) {
        httpEngine.getString(url, params, tag, callBack);
    }

    @Override
    public void getString(String url, Map<String, Object> params, StringCallback callBack, HttpPriority priority) {
        httpEngine.getString(url, params, callBack, priority);
    }

    @Override
    public void getString(String url, Map<String, Object> params, String tag, StringCallback callBack, HttpPriority priority) {
        httpEngine.getString(url, params, tag, callBack, priority);
    }

    @Override
    public void postString(String url, Map<String, Object> params, StringCallback callBack) {
        httpEngine.postString(url, params, callBack);
    }

    @Override
    public void postString(String url, Map<String, Object> params, String tag, StringCallback callBack) {
        httpEngine.postString(url, params, tag, callBack);
    }

    @Override
    public void postString(String url, Map<String, Object> params, StringCallback callBack, HttpPriority priority) {
        httpEngine.postString(url, params, callBack, priority);
    }

    @Override
    public void postString(String url, Map<String, Object> params, String tag, StringCallback callBack, HttpPriority priority) {
        httpEngine.postString(url, params, tag, callBack, priority);
    }

    @Override
    public void postJsonString(String url, Object object, StringCallback callBack) {
        httpEngine.postJsonString(url, object, callBack);
    }

    @Override
    public void getFile(String url, FileCallback callBack) {
        httpEngine.getFile(url, callBack);
    }

    @Override
    public void getFile(String url, Map<String, Object> params, FileCallback callBack) {
        httpEngine.getFile(url, params, callBack);
    }

    @Override
    public void getFile(String url, Map<String, Object> params, String tag, FileCallback callBack) {
        httpEngine.getFile(url, params, tag, callBack);
    }

    @Override
    public void getFile(String url, Map<String, Object> params, FileCallback callBack, HttpPriority priority) {
        httpEngine.getFile(url, params, callBack, priority);
    }

    @Override
    public void getFile(String url, Map<String, Object> params, String tag, FileCallback callBack, HttpPriority priority) {
        httpEngine.getFile(url, params, tag, callBack, priority);
    }

    @Override
    public void upFile(String url, Map<String, Object> params, File file, StringCallback callBack) {
        httpEngine.upFile(url, params, file, callBack);
    }

    @Override
    public void upHead(String url, Map<String, Object> params, File file, StringCallback callBack) {
        httpEngine.upHead(url, params, file, callBack);
    }

    @Override
    public void upFile(String url, Map<String, Object> params, File file, String tag, StringCallback callBack) {
        httpEngine.upFile(url, params, file, tag, callBack);
    }

    @Override
    public void upFile(String url, Map<String, Object> params, File file, StringCallback callBack, HttpPriority priority) {
        httpEngine.upFile(url, params, file, callBack, priority);
    }

    @Override
    public void upFile(String url, Map<String, Object> params, File file, String tag, StringCallback callBack, HttpPriority priority) {
        httpEngine.upFile(url, params, file, tag, callBack, priority);
    }

    @Override
    public void upFiles(String url, Map<String, Object> params, List<File> files, StringCallback callBack) {
        httpEngine.upFiles(url, params, files, callBack);
    }

}
